import Packet from "../net/Packet"

// 角色登录
export default class AccountRoleLogin {
	/**
	 * @param rid 角色ID
	 * @param extParam 扩展参数(json)
	 */
	public constructor(public rid: Long, public extParam: string) { }

	public encode(): Packet {
		const packet = this._encode()
		packet.Encode(2090)
		return packet
	}

	public encodeMsg(): ByteBuffer {
		return this._encode().GetBuffer()
	}

	public static decode(packet: Packet): AccountRoleLogin {
		const rid = packet.ReadUlong()
		const extParam = packet.ReadString()
		return new AccountRoleLogin(rid, extParam)
	}

	private _encode(): Packet {
		const packet = new Packet()
		packet.WriteUlong(this.rid)
		packet.WriteString(this.extParam)
		return packet
	}
}
